package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.main.SharedCardPraiseDAO;
import com.xinghou.platform.model.main.SharedCardPraise;

@Service
public class SharedCardPraiseDAOImpl  {/*
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public SharedCardPraise getSharedCardPraiseByid(Integer Id)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT 	Id,User_id,Card_id,STATUS,Create_time FROM shared_card_praise where Id = ?";
		SharedCardPraise sharedCardPraise = jdbcTemplate.queryForObject(sql, new Object[] {Id}, new SharedCardPraiseMapper());
		CustomerContextHolder.clearCustomerType();
		return sharedCardPraise;
	}

	@Override
	public int updateSharedCardPraise(SharedCardPraise sharedCardPraise)
			throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"UPDATE shared_card_praise SET User_id =? ,Card_id =?,STATUS =?, Create_time =? Where Id =?"	
				);
		Object[] params = {sharedCardPraise.getUserId(), sharedCardPraise.getCardId(), sharedCardPraise.getStatus(), sharedCardPraise.getCreateTime(),sharedCardPraise.getId()
		};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public int saveSharedCardPraise(SharedCardPraise sharedCardPraise)
			throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"INSERT INTO shared_card_praise (User_id,Card_id,STATUS,Create_time)VALUES(?,?,?,?)"
				);
		Object[] params = {sharedCardPraise.getUserId(), sharedCardPraise.getCardId(), sharedCardPraise.getStatus(), sharedCardPraise.getCreateTime()
		};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret =jdbcTemplate.save(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}
   
	@Override
	public SharedCardPraise getSharedCardPraiseBytwo(Integer userId,
			Integer cardId) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT 	Id,User_id,Card_id,STATUS,Create_time FROM shared_card_praise where User_id = ? and Card_id=?";
		SharedCardPraise sharedCardPraise = jdbcTemplate.queryForObject(sql, new Object[] {userId,cardId}, new SharedCardPraiseMapper());
		CustomerContextHolder.clearCustomerType();
		return sharedCardPraise;
	}
	private static final class SharedCardPraiseMapper implements RowMapper<SharedCardPraise> {
		public SharedCardPraise mapRow(ResultSet rs, int rowNum) throws SQLException {
			SharedCardPraise sharedCardPraise = new SharedCardPraise();
			sharedCardPraise.setCardId(rs.getInt("Card_id"));
			sharedCardPraise.setCreateTime(rs.getTimestamp("Create_time"));
			sharedCardPraise.setId(rs.getInt("Id"));
			sharedCardPraise.setStatus(rs.getShort("STATUS"));
			sharedCardPraise.setUserId(rs.getInt("User_id"));
			return sharedCardPraise;
		}
	}

	@Override
	public List<SharedCardPraise> getSharedCardPraiselist() {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		 String sql = "SELECT Id,User_id,Card_id,STATUS,Create_time FROM shared_card_praise";
		  List<SharedCardPraise> list=(List<SharedCardPraise>)jdbcTemplate.query(sql,new SharedCardPraiseMapper());
		return list;
	}
	
	@Override
	public List<SharedCardPraise> getSharedCardPraise(int num, int cardid) {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		 String sql = "SELECT Id,User_id,Card_id,STATUS,Create_time FROM shared_card_praise where Card_id=? and Status=1 and  Id>? ORDER BY Id LIMIT 10";
		  List<SharedCardPraise> SharedCardPraiselist=(List<SharedCardPraise>)jdbcTemplate.query(sql,new Object[] {cardid,num},new SharedCardPraiseMapper());
		return SharedCardPraiselist;
	}

	@Override
	public List<SharedCardPraise> getShareCardPreiseListByCardid(int cardid,
			int id, int rowNum) {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		 String sql = "SELECT Id,User_id,Card_id,STATUS,Create_time FROM shared_card_praise where Card_id=? and Status=1 and  Id<? ORDER BY Id DESC LIMIT ?";
		  List<SharedCardPraise> SharedCardPraiselist=(List<SharedCardPraise>)jdbcTemplate.query(sql,new Object[] {cardid,id,rowNum},new SharedCardPraiseMapper());
		return SharedCardPraiselist;
	}

	@Override
	public SharedCardPraise getSharedCardPraiseStatusByid(int id, int userId)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT Id,User_id,Card_id,STATUS,Create_time FROM shared_card_praise where Card_id = ? AND User_id=?";
		SharedCardPraise sharedCardPraise = jdbcTemplate.queryForObject(sql, new Object[] {id,userId}, new SharedCardPraiseMapper());
		CustomerContextHolder.clearCustomerType();
		return sharedCardPraise;
	}

	@Override
	public List<SharedCardPraise> getSharedCardByUserId(int userId, Timestamp time,
			int limit) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT Id,User_id,Card_id,STATUS,Create_time FROM shared_card_praise where Status=1 and User_id=? and Create_time<? ORDER BY Create_time DESC LIMIT ?";
		List<SharedCardPraise> SharedCardPraiselist=(List<SharedCardPraise>)jdbcTemplate.query(sql,new Object[] {userId,time,limit},new SharedCardPraiseMapper());
		return SharedCardPraiselist;
	}*/
}
